package com.yayo.mangement.conf;

import com.yayo.mangement.converter.ColumnConverter;
import com.yayo.mangement.converter.db.MySqlColumnConverter;
import com.yayo.mangement.authentication.enums.DbTypeEnum;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DbConfig {

    private static final String DB_TYPE = "mysql";

    private static String DB_NAME;

    //初始化数据库类型对应java类型转换，目前只支持mysql数据类型
    public static final ColumnConverter columnConverter;

    @Value("${spring.datasource.name}")
    private void setDbName(String dbName){
        this.DB_NAME = dbName;
    }

    public static String getDbName(){
        return DB_NAME;
    }

    static{
        if(DbTypeEnum.MYSQL.getCode().equals(DB_TYPE)){
            columnConverter = new MySqlColumnConverter();
        }else{
            columnConverter = new MySqlColumnConverter();
        }
    }
}
